[アップデート] Amazon ECS のサービスのデプロイ履歴が 90 日間保管されるようになりました

[アップデート] Amazon ECS のサービスのデプロイ履歴が 90 日間保管されるようになりました

各サービスデプロイで利用したリビジョンや設定値を 90 日間保持してくれるため、トラブルシューティングに役立ちそうです。
Clock Icon2024.10.31

こんにちは!AWS 事業本部コンサルティング部のたかくに(@takakuni_)です。

What's new には出てきていないのですが、 Amazon ECS のサービスのデプロイ履歴が 90 日間保管されるようになりました。今まではマネジメントコンソール上で、デプロイが落ち着けばしれっと消えていたのですが、ついに保持されるようになりましたね。

2024 年 10 月 25 日ごろ(タイムゾーンが書かれていない)以降の ECS Service のローリングアップデートのデプロイは、 90 日間記録が保持され、マネジメントコンソールや API, AWS CLI で確認できるようになったようです。

You can view the most recent 90-day history for deployments created on or after October 25, 2024 by using the console, API, and the AWS CLI.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-deployment.html

デプロイを遡れるのは地味に嬉しいですね。障害やインシデント時の復旧にも役立ちそうです。

やってみる

今回、ListServiceDeployments, DescribeServiceDeployments, DescribeServiceRevisions の 3 つの API が増えました。

https://awsapichanges.com/archive/changes/0b82f0-ecs.html

ECS サービスにデプロイしてみて、各 API の情報を見てみましょう。今回は CloudShell で AWS CLI を利用して確認します。

執筆時点(2024 年 10 月)の AWS CLI のバージョンは、 v2.18.16 だったため、v2.18.18 まで引き上げます。

[cloudshell-user@ip-10-134-22-30 ~]$ aws --version
aws-cli/2.18.16 Python/3.12.6 Linux/6.1.112-122.189.amzn2023.x86_64 exec-env/CloudShell exe/x86_64.amzn.2023

https://github.com/aws/aws-cli/commit/78b92148ff199c368db0a04882c814ce7ce74648

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
aws --version

https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/getting-started-install.html#getting-started-install-instructions

AWS CLI のバージョンが、v2.18.18 以上に更新されていれば OK です。

[cloudshell-user@ip-10-134-22-30 ~]$ aws --version
aws-cli/2.18.18 Python/3.12.6 Linux/6.1.112-122.189.amzn2023.x86_64 exec-env/CloudShell exe/x86_64.amzn.2023

ListServiceDeployments

まずは ListServiceDeployments でサービスのデプロイ履歴を確認してみます。 Service 名は各々変更してください。

aws ecs list-service-deployments --service nginx-samples

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServiceDeployments.html

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/list-service-deployments.html

2 回デプロイされたことがわかりますね。

[cloudshell-user@ip-10-134-22-30 ~]$ aws ecs list-service-deployments --service nginx-samples
{
    "serviceDeployments": [
        {
            "serviceDeploymentArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-deployment/default/nginx-samples/8ZuT0Mg1cupzfMEgHVCC0",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "startedAt": "2024-10-31T11:18:47.548000+00:00",
            "createdAt": "2024-10-31T11:18:47.268000+00:00",
            "finishedAt": "2024-10-31T11:21:54.138000+00:00",
            "targetServiceRevisionArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/4011895814516657029",
            "status": "SUCCESSFUL"
        },
        {
            "serviceDeploymentArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-deployment/default/nginx-samples/F3MV2mrljCDg-BWDhttmd",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "startedAt": "2024-10-31T11:05:42.581000+00:00",
            "createdAt": "2024-10-31T11:05:39.382000+00:00",
            "finishedAt": "2024-10-31T11:08:40.627000+00:00",
            "targetServiceRevisionArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/8016324381877427299",
            "status": "SUCCESSFUL"
        }
    ]
}

マネジメントコンソール上でも確認できるのかなと思っていたのですが、まだ表示されていない模様でした。

2024-10-31 at 20.26.31-サービスデプロイ  Elastic Container Service  ap-northeast-1.png

DescribeServiceDeployments

では、 DescribeServiceDeployments で List で取得したサービスデプロイの詳細を確認してみます。

SERVICE_DEPLOYMENT_ARNS=$(aws ecs list-service-deployments --service nginx-samples --query serviceDeployments[].serviceDeploymentArn --output text)
aws ecs describe-service-deployments --service-deployment-arns $SERVICE_DEPLOYMENT_ARNS --no-cli-pager

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServiceDeployments.html

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/describe-service-deployments.html

デプロイの詳細が出てきました。sourceServiceRevisionstargetServiceRevision が記載されてて、どのリビジョンのタスクをどれ程リクエストしたのか見えてて、とても便利ですね。サービス作成時の sourceServiceRevisions は空になっていますね。

[cloudshell-user@ip-10-134-22-30 ~]$ SERVICE_DEPLOYMENT_ARNS=$(aws ecs list-service-deployments --service nginx-samples --query serviceDeployments[].serviceDeploymentArn --output text)
[cloudshell-user@ip-10-134-22-30 ~]$ aws ecs describe-service-deployments --service-deployment-arns $SERVICE_DEPLOYMENT_ARNS --no-cli-pager
{
    "serviceDeployments": [
        {
            "serviceDeploymentArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-deployment/default/nginx-samples/8ZuT0Mg1cupzfMEgHVCC0",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "createdAt": "2024-10-31T11:18:47.268000+00:00",
            "startedAt": "2024-10-31T11:18:47.548000+00:00",
            "finishedAt": "2024-10-31T11:21:54.138000+00:00",
            "updatedAt": "2024-10-31T11:21:54.138000+00:00",
            "sourceServiceRevisions": [
                {
                    "arn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/8016324381877427299",
                    "requestedTaskCount": 0,
                    "runningTaskCount": 0,
                    "pendingTaskCount": 0
                }
            ],
            "targetServiceRevision": {
                "arn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/4011895814516657029",
                "requestedTaskCount": 1,
                "runningTaskCount": 1,
                "pendingTaskCount": 0
            },
            "status": "SUCCESSFUL",
            "deploymentConfiguration": {
                "deploymentCircuitBreaker": {
                    "enable": true,
                    "rollback": true
                },
                "maximumPercent": 200,
                "minimumHealthyPercent": 100,
                "alarms": {
                    "alarmNames": [],
                    "rollback": false,
                    "enable": false
                }
            },
            "deploymentCircuitBreaker": {
                "status": "MONITORING_COMPLETE",
                "failureCount": 0,
                "threshold": 3
            },
            "alarms": {
                "status": "DISABLED"
            }
        },
        {
            "serviceDeploymentArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-deployment/default/nginx-samples/F3MV2mrljCDg-BWDhttmd",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "createdAt": "2024-10-31T11:05:39.382000+00:00",
            "startedAt": "2024-10-31T11:05:42.581000+00:00",
            "finishedAt": "2024-10-31T11:08:40.627000+00:00",
            "updatedAt": "2024-10-31T11:08:40.627000+00:00",
            "sourceServiceRevisions": [],
            "targetServiceRevision": {
                "arn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/8016324381877427299",
                "requestedTaskCount": 1,
                "runningTaskCount": 1,
                "pendingTaskCount": 0
            },
            "status": "SUCCESSFUL",
            "deploymentConfiguration": {
                "deploymentCircuitBreaker": {
                    "enable": true,
                    "rollback": true
                },
                "maximumPercent": 200,
                "minimumHealthyPercent": 100,
                "alarms": {
                    "alarmNames": [],
                    "rollback": false,
                    "enable": false
                }
            },
            "deploymentCircuitBreaker": {
                "status": "MONITORING_COMPLETE",
                "failureCount": 0,
                "threshold": 3
            },
            "alarms": {
                "status": "DISABLED"
            }
        }
    ],
    "failures": []
}

DescribeServiceRevisions

最後に DescribeServiceRevisions でサービスのデプロイメントで使われたタスク定義リビジョンを表示してみます。

SERVICE_REVISION_ARNS=$(aws ecs list-service-deployments --service nginx-samples --query serviceDeployments[].targetServiceRevisionArn --output text)
aws ecs describe-service-revisions --service-revision-arns $SERVICE_REVISION_ARNS --no-cli-pager

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServiceRevisions.html

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecs/describe-service-revisions.html

各デプロイメントで使われたタスク定義の詳細が表示されていますね。 guardDutyEnabled キーがあるのが少しオモシロイです。

[cloudshell-user@ip-10-134-22-30 ~]$ SERVICE_REVISION_ARNS=$(aws ecs list-service-deployments --service nginx-samples --query serviceDeployments[].targetServiceRevisionArn --output text)
[cloudshell-user@ip-10-134-22-30 ~]$ aws ecs describe-service-revisions --service-revision-arns $SERVICE_REVISION_ARNS --no-cli-pager
{
    "serviceRevisions": [
        {
            "serviceRevisionArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/4011895814516657029",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/nginx-samples:2",
            "launchType": "FARGATE",
            "platformVersion": "1.4.0",
            "platformFamily": "Linux",
            "loadBalancers": [],
            "serviceRegistries": [],
            "networkConfiguration": {
                "awsvpcConfiguration": {
                    "subnets": [
                        "subnet-05a65d661b1a74795",
                        "subnet-0deef2f54bbb1a19b",
                        "subnet-0f5238f9112b400e1"
                    ],
                    "securityGroups": [
                        "sg-0e919f1eaaab40ae9"
                    ],
                    "assignPublicIp": "ENABLED"
                }
            },
            "containerImages": [
                {
                    "containerName": "nginx",
                    "imageDigest": "sha256:696e6a7ecc4ccf595af5aec8e395967fbca01d214ec79a9ee536de56a0135c85",
                    "image": "123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/nginx-samples:v2"
                }
            ],
            "guardDutyEnabled": false,
            "createdAt": "2024-10-31T11:18:42.933000+00:00"
        },
        {
            "serviceRevisionArn": "arn:aws:ecs:ap-northeast-1:123456789012:service-revision/default/nginx-samples/8016324381877427299",
            "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/default/nginx-samples",
            "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/default",
            "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/nginx-samples:1",
            "launchType": "FARGATE",
            "platformVersion": "1.4.0",
            "platformFamily": "Linux",
            "networkConfiguration": {
                "awsvpcConfiguration": {
                    "subnets": [
                        "subnet-05a65d661b1a74795",
                        "subnet-0f5238f9112b400e1",
                        "subnet-0deef2f54bbb1a19b"
                    ],
                    "securityGroups": [
                        "sg-0e919f1eaaab40ae9"
                    ],
                    "assignPublicIp": "ENABLED"
                }
            },
            "containerImages": [
                {
                    "containerName": "nginx",
                    "imageDigest": "sha256:f137d1b066c8010b5dcea233398ed4c114209c73bde0a121137ea148660affec",
                    "image": "123456789012.dkr.ecr.ap-northeast-1.amazonaws.com/nginx-samples:v1"
                }
            ],
            "guardDutyEnabled": false,
            "serviceConnectConfiguration": {
                "enabled": false
            },
            "createdAt": "2024-10-31T11:05:36.771000+00:00"
        }
    ],
    "failures": []
}

参考情報

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-deployment.html

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-revision.html

まとめ

以上、「Amazon ECS のサービスのデプロイ履歴が 90 日間保管されるようになりました。」でした。

障害以外の観点でも、どのデプロイが成功してどのデプロイが失敗したのか日頃の調査にも便利な機能だと思いました。

このブログがどなたかの参考になれば幸いです。

AWS 事業本部コンサルティング部のたかくに(@takakuni_)でした!

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.